//Classe dialog
$(document).ready( function() {
    sempab = window.sempab || {};
    sempab.alert = {
        callback: null,
        showMessage: function(message, args) {
            //Valores default
            args = $.extend({
                btnValue: "Confirm",
                timeout: null,
                callback: null
            }, args);
            sempab.alert.callback = args.callback;
            $('#alert-message').html(message);
            if (args['buttons']) {
                $('#alert-buttons').html(args['buttons'].replace('&confirm', '<input id="alert-confirm" class="button" type="button" value="'+args['btnValue']+'" />'));
            } else {
                $('#alert-buttons').html('<input id="alert-confirm" class="button" type="button" value="'+args['btnValue']+'" />');
            }
            $('#alert-confirm').val(args['btnValue']);
            $('#alert').css('top', window.pageYOffset + 120);
            $('#dark').height($(document).height());
            $('#dark').show();
            $('#alert').show( function() {
                sempab.alert.bind();
                //Timeout implementation
                if (args['timeout'] != null)
                    $.doTimeout('alertTimer', args['timeout'], function() {
                        sempab.alert.hide();
                    });
            });
        },
        showConfirm: function(message, args) {
            //Valores default
            args = $.extend({
                btnConfirm: "Confirm",
                btnCancel: "Cancel",
                callback: null
            }, args);
            sempab.alert.callback = args.callback;
            $('#alert-message').html(message);
            $('#alert-buttons').html('<input id="alert-confirm" class="button" type="button" value="'+args['btnConfirm']+'" /> <input id="alert-cancel" class="button red" type="button" value="'+args['btnCancel']+'" />');
            $('#alert').css('top', window.pageYOffset + 120);
            $('#dark').height($(document).height());
            $('#dark').show();
            $('#alert').show( function() {
                sempab.alert.bind();
            });
        },
        showLoader: function() {
            $('#alert-message').html("<div style='text-align: center; padding-top: 90px;'><img src='images/loaders/2.gif' /></div>");
            $('#alert-buttons').html("<p>&nbsp;</p>");
            $('#alert').css('top', window.pageYOffset + 120);
            $('#dark').height($(document).height());
            $('#dark').show();
            $('#alert').show();
        },
        hideLoader: function() {
            $('#dark').hide();
            $('#alert').hide();
        },
        hide: function() {
            sempab.alert.unbind();
            $('#dark').hide();
            $('#alert').fadeOut(sempab.alert.callback);
        },
        //Click events
        bind: function() {
            $('#alert-confirm').click( function() {
                $.doTimeout('alertTimer', false);
                sempab.alert.hide();
            });
            $('#alert-cancel').click( function() {
                sempab.alert.callback = null;
                sempab.alert.hide();
            });
        },
        unbind: function() {
            $('#alert-confirm').unbind();
        }
    };
    window.sempab = sempab;
}).ready( function() {
    //Elementos UI
    //Accordion
    //Input File
    $(".inputFile-field").change( function() {
        $(this).prev().html($(this).val());
    });
}).ready( function() {
    //Funções iniciais
    $('#loader').height($(document).height());
    $('#dark').height($(document).height());
    $("abbr.timeago").timeago();
    
    
    $('#loader').fadeOut('slow');
    //This starts the page
    if (typeof(sempab.view) != 'undefined') {
        if (typeof(sempab.view.init) != 'undefined') {
            sempab.view.init();
            sempab.view.bind();
        }
    }
});